package com.simen.kv.sample;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.simen.absadapter.AbsAdapter;
import com.simen.kv.KV;
import com.simen.kv.KVManager;

import java.util.ArrayList;
import java.util.List;

public class LauncherActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        KVManager.getInstance().setWriteAheadLoggingEnabled(true);

        List<String> list = new ArrayList<>();
        list.add("SimpleKV Sample");
        list.add("Sort Sample");
        list.add("Helper");
        setListAdapter(new AbsAdapter<String>(this, list, android.R.layout.simple_list_item_1) {
            @Override
            protected boolean onItemAdapter(AbsViewHolder viewHolder, String element, int
                    position) {
                viewHolder.setTextOrButton(android.R.id.text1, element);
                return false;
            }
        });
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        if (position == 0) {
            startActivity(new Intent(LauncherActivity.this, MainActivity.class));
        } else if (position == 1) {
            startActivity(new Intent(LauncherActivity.this, SortActivity.class));
        } else if (position == 2) {
            startActivity(new Intent(LauncherActivity.this, HelperActivity.class));
        }
    }
}
